package com.sjf.day01;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author <sjf753@qq.com>
 * @since 2021/12/7 13:59
 **/
public class test03 {

    public static void main(String[] args) {
        //List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
        //// 获取对应的平方数
        //List<Integer> collect = numbers.stream().map(i -> i * i).collect(Collectors.toList());
        //System.out.println(collect);

        //Random random = new Random(50);
        //random.ints().limit(10).sorted().forEach(System.out::println);

        //List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
        //long count = strings.parallelStream().filter(string -> string.isEmpty()).count();
        //List<String> list = strings.stream().filter(string->!string.isEmpty()).collect(Collectors.toList());
        //System.out.println(list);
        //String s = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.joining(","));
        //System.out.println(s);

        //List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
        //IntSummaryStatistics statistics = numbers.stream().mapToInt((x) -> x).summaryStatistics();
        //System.out.println(statistics);

        /**
         * 根据Java 7的写法，写出对应Java 8的Stream
         */

        // 计算空字符串
        List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
        String s1 = strings.stream().findFirst().get();
        System.out.println("s1="+s1);

        long count = strings.stream().filter(String::isEmpty).count();
        System.out.println(strings+"对应的空字符串个数为"+count);
        // 删除空字符串
        List<String> list1 = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());
        System.out.println("删除空字符串后的list:"+list1);
        // 删除空字符串，并使用逗号把它们合并起来
        String s = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.joining(","));
        System.out.println("删除空串并且合并后的字符串为："+s);
        // 获取列表元素平方数
        List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
        List<Integer> list = numbers.stream().map(a -> a * a).collect(Collectors.toList());
        System.out.println("numbers对应数组的平方数组为："+list);
        //获取numbers对应的最大数，最小数，和值等
        IntSummaryStatistics statistics = numbers.stream().mapToInt(x -> x).summaryStatistics();
        System.out.println(statistics.toString());
        //输出随机10个数
        //Random random = new Random();
        //random.ints().limit(10).sorted().forEach(System.out::println);
        //并行处理
        long count1 = strings.stream().filter(String::isEmpty).count();
        System.out.println(strings+"空字符串的数量："+count1);

        Collections.sort(strings, String::compareTo);
        System.out.println(strings);
    }
}
